<!DOCTYPE html>
<html
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
    xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
    layout:decorate="~{layout}">

<head>
    <title>Views</title>
</head>

<body>
<section layout:fragment="content">
    <div class="container">

        <div class="row" th:if="${clustersById.isEmpty()}">
            <!-- No Clusters Found -->
            <div class="col-lg-12">
                <div class="card">
                    <div class="alert alert-warning" role="alert">
                        <h4 class="alert-heading"><strong>No Kafka Clusters Found</strong></h4>
                        <p>
                            It looks like you have no Kafka Clusters configured yet!<br/>
                        </p>
                        <p class="mb-0">
                            <span sec:authorize="hasRole('ROLE_ADMIN')">
                                Let's head over and set one up now!
                                <a href="/configuration/cluster/create">Setup new Cluster</a>
                            </span>
                            <span sec:authorize="!hasRole('ROLE_ADMIN')">
                                Ask an Administrator to configure a cluster.
                            </span>
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <div class="row" th:if="${!clustersById.isEmpty()} and ${viewList.isEmpty()}">
            <!-- No Views Found -->
            <div class="col-lg-12">
                <div class="card">
                    <div class="alert alert-warning" role="alert">
                        <h4 class="alert-heading"><strong>No Views Found</strong></h4>
                        <p>
                            It looks like you have no Views configured yet!<br/>
                        </p>
                        <p class="mb-0">
                            <span sec:authorize="hasRole('ROLE_ADMIN')">
                                Let's head over and set one up now!
                                <a href="/configuration/view/create">Setup new View</a>
                            </span>
                            <span sec:authorize="!hasRole('ROLE_ADMIN')">
                                Ask an Administrator to configure a view.
                            </span>
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <div class="row" th:if="${not clustersById.isEmpty()} and ${not viewList.isEmpty()}">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header" th:if="${clusterName != null}">
                        <i class="fa fa-align-justify"></i>
                        Views for <b>[[${clusterName}]]</b> Cluster
                    </div>
                    <div class="card-header" th:if="${clusterName == null}">
                        <i class="fa fa-align-justify"></i>
                        All Views
                    </div>
                    <div class="card-body">
                        <table class="table table-bordered table-striped table-sm">
                            <thead>
                            <tr>
                                <th>View</th>
                                <th>Topic</th>
                                <th>Cluster</th>
                                <th colspan="2"></th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="view : ${viewList}">
                                <td th:text="${view.name}"></td>
                                <td th:text="${view.topic}"></td>
                                <td>
                                    <a th:href="'/cluster/' + ${view.cluster.id}" th:text="${clustersById.get(view.cluster.id).name}"></a>
                                </td>
                                <td>
                                    <a th:href="'/view/' + ${view.id}">Browse</a>
                                </td>
                                <td>
                                    <a th:href="'/stream/' + ${view.id}">Stream</a>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <!--/.col-->
        </div>
    </div>
</section>

</body>
</html>